#include "server.hpp"
void OnMessage(const PtrConnection &conn, Buffer *buf)
{
    std::cout << buf->ReadPosition() << std::endl;
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "Hello World";
    conn->Send(str.c_str(), str.size());
}
void ConnectionDestroy(const PtrConnection &conn)
{
    std::cout << "Closed Connection:" << conn.get() << std::endl;
}
void OnConnected(const PtrConnection &conn)
{
    std::cout << "NEW CONNECTION:" << conn.get() << std::endl;
}

int main(void)
{
    TcpServer test(8500);
    test.SetMessageCallback(std::bind(OnMessage, std::placeholders::_1, std::placeholders::_2));
    test.SetClosedCallback(std::bind(ConnectionDestroy, std::placeholders::_1));
    test.SetConnectedCallback(std::bind(OnConnected, std::placeholders::_1));
    test.SetThreadCount(2);
    test.Start();
    return 0;
}